//
//  MTShopModel.m
//  TestPrj
//
//  Created by 朱铅峰 on 2020/6/22.
//  Copyright © 2020 Xing. All rights reserved.
//

#import "MTShopSingleModel.h"
#import "MTProduct.h"
#import "MTProductGroup.h"

@interface MTShopSingleModel()

proStrong NSArray *categoryArray;

@end

@implementation MTShopSingleModel

+ (instancetype)sharedInstance {
    
    static dispatch_once_t once;
    static id __singleton__;
    dispatch_once( &once, ^{ __singleton__ = [[self alloc] init]; });
    return __singleton__;
}

- (instancetype)sharedInstance {
    
    return [[self class] sharedInstance];
}

- (NSArray<MTProductCategory *> *)categoryArray {
    
    if (!_categoryArray) {
        
        __block NSMutableArray *categoryArray = [NSMutableArray array];
        
        NSArray *iconNames = @[@"雪",@"小雨",@"多云",@"大雨",@"晴",@"lakeside_sunset",@"timg",@"red"];
        
        NSArray *categoryNames = @[@"鞋子",@"帽子",@"电脑",@"手机",@"桌子",@"杯子",@"家电",@"车子",@"猫",@"狗",@"沙发",@"水",@"键盘",@"鼠标",@"显示器",@"眼睛",@"硬盘",@"衣服"];
        
        [categoryNames enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            NSString *cateName = (NSString *)obj;
            NSInteger groupCount = [Utils randomNumberFrom:1 to:5];
            NSMutableArray *groupList = [NSMutableArray array];
            
            for (int i=0; i<groupCount; i++) {
                NSString *groupName = [NSString stringWithFormat:@"分类%d",i+1];
                NSMutableArray *productList = [NSMutableArray array];
                NSInteger productCount = [Utils randomNumberFrom:5 to:10];
                for (int j=0; j<productCount; j++) {
                    NSString *pName= [NSString stringWithFormat:@"%@%d",cateName,(int)[Utils randomNumberFrom:10000 to:30000]];
                    MTProduct *product = [MTProduct new];
                    product.title = pName;
                    product.iconName = iconNames[(int)arc4random()%iconNames.count];
                    [productList addObject:product];
                }
                
                MTProductGroup *group = [MTProductGroup new];
                group.name = groupName;
                group.productList = productList;
                [groupList addObject:group];
            }
            
            MTProductCategory *category = [MTProductCategory new];
            category.name = cateName;
            category.productGroupList = groupList;
            
            [categoryArray addObject:category];
        }];
        
        _categoryArray = categoryArray;
    }
    
    return _categoryArray;
}

//从初始位置滑到顶部与导航条无缝对接，需要的最大距离
- (CGFloat)maxOffsetY {
    
    return 150 + 48 - kNavBarHeight - 28;
}

//开始改变的偏移量
- (CGFloat)startChangeY {
    
    return 21;
}

/// 店铺头部视图高度
- (CGFloat)headerHeight {
    
    return 150;
}

@end
